<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>在 CentOS 上搭建 PHP 服务器环境 | Aurthur Article</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在CentOS上搭建PHP服务器环境在CentOS上搭建PHP服务器环境
方案一安装apache:
1yum install httpd httpd-devel
启动apache:
1/etc/init.d/httpd start
此时输入服务器的IP地址，应该看到apache的服务页面，端口不用输，apache默认就是使用80端口">
<meta property="og:type" content="article">
<meta property="og:title" content="在 CentOS 上搭建 PHP 服务器环境">
<meta property="og:url" content="http://aurthur.gitos.cn/Aurthur-2015/Install-PHP-In-Centos.html">
<meta property="og:site_name" content="Aurthur Article">
<meta property="og:description" content="在CentOS上搭建PHP服务器环境在CentOS上搭建PHP服务器环境
方案一安装apache:
1yum install httpd httpd-devel
启动apache:
1/etc/init.d/httpd start
此时输入服务器的IP地址，应该看到apache的服务页面，端口不用输，apache默认就是使用80端口">
<meta property="og:updated_time" content="2017-01-07T12:46:31.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="在 CentOS 上搭建 PHP 服务器环境">
<meta name="twitter:description" content="在CentOS上搭建PHP服务器环境在CentOS上搭建PHP服务器环境
方案一安装apache:
1yum install httpd httpd-devel
启动apache:
1/etc/init.d/httpd start
此时输入服务器的IP地址，应该看到apache的服务页面，端口不用输，apache默认就是使用80端口">
  
  
    <link rel="icon" href="/uploads/blog.ico">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="/uploads/blog.png" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">Aurthur</a></h1>
		</hgroup>

		
		<p class="header-subtitle">Aurthur Blog</p>
		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						
						<div class="icon-wrap icon-me hide" data-idx="3">
							<div class="user"></div>
							<div class="shoulder"></div>
						</div>
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						
						<li>关于我</li>
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
								<a class="github" target="_blank" href="https://github.com/aurthurxlc" title="github">github</a>
					        
								<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/aurthur" title="zhihu">zhihu</a>
					        
								<a class="mail" target="_blank" href="/aurthurxlc@gmail.com" title="mail">mail</a>
					        
								<a class="google" target="_blank" href="https://plus.google.com/u/0/110645540964195673210" title="google">google</a>
					        
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						<a href="/tags/ADB/" style="font-size: 10px;">ADB</a> <a href="/tags/API/" style="font-size: 10px;">API</a> <a href="/tags/Android/" style="font-size: 10px;">Android</a> <a href="/tags/Apache/" style="font-size: 12.5px;">Apache</a> <a href="/tags/CentOS/" style="font-size: 15px;">CentOS</a> <a href="/tags/Centos/" style="font-size: 12.5px;">Centos</a> <a href="/tags/Chkconfig/" style="font-size: 10px;">Chkconfig</a> <a href="/tags/Electron/" style="font-size: 10px;">Electron</a> <a href="/tags/FTP/" style="font-size: 10px;">FTP</a> <a href="/tags/FastCGI/" style="font-size: 10px;">FastCGI</a> <a href="/tags/Iterm/" style="font-size: 10px;">Iterm</a> <a href="/tags/Java/" style="font-size: 15px;">Java</a> <a href="/tags/Kernel/" style="font-size: 10px;">Kernel</a> <a href="/tags/Linux/" style="font-size: 17.5px;">Linux</a> <a href="/tags/Mac/" style="font-size: 12.5px;">Mac</a> <a href="/tags/Mirror/" style="font-size: 10px;">Mirror</a> <a href="/tags/Mysql/" style="font-size: 12.5px;">Mysql</a> <a href="/tags/Nginx/" style="font-size: 12.5px;">Nginx</a> <a href="/tags/PHP/" style="font-size: 20px;">PHP</a> <a href="/tags/RESTful/" style="font-size: 10px;">RESTful</a> <a href="/tags/Regular-Expression/" style="font-size: 10px;">Regular Expression</a> <a href="/tags/SSH/" style="font-size: 10px;">SSH</a> <a href="/tags/SSL/" style="font-size: 10px;">SSL</a> <a href="/tags/Sass/" style="font-size: 10px;">Sass</a> <a href="/tags/Server/" style="font-size: 10px;">Server</a> <a href="/tags/Terminal/" style="font-size: 10px;">Terminal</a> <a href="/tags/Ubuntu/" style="font-size: 10px;">Ubuntu</a> <a href="/tags/VPN/" style="font-size: 10px;">VPN</a> <a href="/tags/Vagrant/" style="font-size: 10px;">Vagrant</a> <a href="/tags/Volume/" style="font-size: 12.5px;">Volume</a> <a href="/tags/Web/" style="font-size: 12.5px;">Web</a> <a href="/tags/Windows/" style="font-size: 10px;">Windows</a> <a href="/tags/compile/" style="font-size: 10px;">compile</a> <a href="/tags/dd/" style="font-size: 10px;">dd</a> <a href="/tags/develop-tools/" style="font-size: 10px;">develop tools</a> <a href="/tags/gitlab/" style="font-size: 10px;">gitlab</a> <a href="/tags/go/" style="font-size: 12.5px;">go</a> <a href="/tags/gzip/" style="font-size: 10px;">gzip</a> <a href="/tags/hook/" style="font-size: 10px;">hook</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/mod-php/" style="font-size: 10px;">mod_php</a> <a href="/tags/ntp/" style="font-size: 10px;">ntp</a> <a href="/tags/supervisor/" style="font-size: 10px;">supervisor</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/zimg/" style="font-size: 12.5px;">zimg</a>
					</div>
				</section>
				
				
				

				
				
				<section class="switch-part switch-part3">
				
					<div id="js-aboutme">true</div>
				</section>
				
			</div>
		</div>
	</header>				
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">Aurthur</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				<img lazy-src="/uploads/blog.png" class="js-avatar">
			</div>
			<hgroup>
			  <h1 class="header-author">Aurthur</h1>
			</hgroup>
			
			<p class="header-subtitle">Aurthur Blog</p>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/aurthurxlc" title="github">github</a>
			        
						<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/aurthur" title="zhihu">zhihu</a>
			        
						<a class="mail" target="_blank" href="/aurthurxlc@gmail.com" title="mail">mail</a>
			        
						<a class="google" target="_blank" href="https://plus.google.com/u/0/110645540964195673210" title="google">google</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>
      <div class="body-wrap"><article id="post-Install-PHP-In-Centos" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/Aurthur-2015/Install-PHP-In-Centos.html" class="article-date">
  	<time datetime="2017-01-07T12:46:31.000Z" itemprop="datePublished">2017-01-07</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      在 CentOS 上搭建 PHP 服务器环境
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
	<div class="article-tag tagcloud">
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CentOS/">CentOS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/PHP/">PHP</a></li></ul>
	</div>

        
	<div class="article-category tagcloud">
	<a class="article-category-link" href="/categories/Technical/">Technical</a>
	</div>


        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="在CentOS上搭建PHP服务器环境">在CentOS上搭建PHP服务器环境</h1><p>在CentOS上搭建PHP服务器环境</p>
<h2 id="方案一">方案一</h2><p>安装apache:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install httpd httpd-devel</span><br></pre></td></tr></table></figure>
<p>启动apache:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/httpd start</span><br></pre></td></tr></table></figure>
<p>此时输入服务器的IP地址，应该看到apache的服务页面，端口不用输，apache默认就是使用80端口<br><a id="more"></a><br>安装mysql:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install mysql mysql-server mysql mysql-deve</span><br></pre></td></tr></table></figure></p>
<p>启动mysql:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/mysqld start</span><br></pre></td></tr></table></figure></p>
<p>安装php<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install php php-devel</span><br></pre></td></tr></table></figure></p>
<p>重启apache使php生效<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/httpd restart</span><br></pre></td></tr></table></figure></p>
<p>此时可以在目录：/var/www/html/下建立一个PHP文件<br>代码：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php phpinfo(); ?&gt;</span><br></pre></td></tr></table></figure></p>
<p>然后访问这个文件，就能看到PHP的一些信息，php.ini配置文件的路径可以在这个页面上看到</p>
<p>安装php的扩展<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc</span><br></pre></td></tr></table></figure></p>
<p>安装完扩展之后需要再次重启apache<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/httpd restart</span><br></pre></td></tr></table></figure></p>
<p>安装php的相关组件<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">yum search php (搜索php相关的组件)</span><br><span class="line"></span><br><span class="line">yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc</span><br><span class="line"></span><br><span class="line">安装完成后重启apache服务</span><br><span class="line"></span><br><span class="line">sudo service httpd restart</span><br></pre></td></tr></table></figure></p>
<hr>
<h2 id="方案二">方案二</h2><p>您也可以使用一键自动部署环境的工具，请参见网友开发的这个工具<br><a href="http://www.centos.bz/2013/08/ezhttp-tutorial/" target="_blank" rel="external">http://www.centos.bz/2013/08/ezhttp-tutorial/</a></p>
<hr>
<h2 id="路径解析">路径解析</h2><p>apache<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">如果采用RPM包安装，安装路径应在 /etc/httpd目录下</span><br><span class="line">apache配置文件:/etc/httpd/conf/httpd.conf</span><br><span class="line">Apache模块路径：/usr/sbin/apachectl</span><br><span class="line">web目录:/var/www/html</span><br><span class="line">如果采用源代码安装，一般默认安装在/usr/<span class="built_in">local</span>/apache2目录下</span><br></pre></td></tr></table></figure></p>
<p>php<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">如果采用RPM包安装，安装路径应在 /etc/目录下</span><br><span class="line">php的配置文件:/etc/php.ini</span><br><span class="line">如果采用源代码安装，一般默认安装在/usr/<span class="built_in">local</span>/lib目录下</span><br><span class="line">php配置文件: /usr/<span class="built_in">local</span>/lib/php.ini</span><br><span class="line">或/usr/<span class="built_in">local</span>/php/etc/php.ini</span><br></pre></td></tr></table></figure></p>
<p>mysql<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">如果采用RPM包安装，安装路径应在/usr/share/mysql目录下</span><br><span class="line">mysqldump文件位置：/usr/bin/mysqldump</span><br><span class="line">mysqli配置文件:</span><br><span class="line">/etc/my.cnf或/usr/share/mysql/my.cnf</span><br><span class="line">mysql数据目录在/var/lib/mysql目录下</span><br><span class="line">如果采用源代码安装，一般默认安装在/usr/<span class="built_in">local</span>/mysql目录下</span><br></pre></td></tr></table></figure></p>
<h2 id="apache重启（docker容器内）">apache重启（docker容器内）</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apachectl -k start</span><br></pre></td></tr></table></figure>
<h2 id="设置/删除环境变量">设置/删除环境变量</h2><h3 id="设置：">设置：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span>变量名=变量值</span><br></pre></td></tr></table></figure>
<h4 id="删除：">删除：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">unset</span>变量名</span><br></pre></td></tr></table></figure>
<h1 id="Yum安装php5-5">Yum安装php5.5</h1><p>先删除旧的php版本<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum remove php  php-bcmath php-cli php-common  php-devel php-fpm    php-gd php-imap  php-ldap php-mbstring php-mcrypt php-mysql   php-odbc   php-pdo   php-pear  php-pecl-igbinary  php-xml php-xmlrpc</span><br></pre></td></tr></table></figure></p>
<p>添加源<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm</span><br></pre></td></tr></table></figure></p>
<p>安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install php55w  php55w-bcmath php55w-cli php55w-common  php55w-devel php55w-fpm    php55w-gd php55w-imap  php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql   php55w-odbc   php55w-pdo   php55w-pear  php55w-pecl-igbinary  php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache</span><br></pre></td></tr></table></figure>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/Aurthur-2015/Install-SSL-Certificate-In-Server.html" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          服务器安全之配置SSL访问实战
        
      </div>
    </a>
  
  
    <a href="/Aurthur-2015/Ftp-Linux-Comand.html" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">FTP 常用命令详解</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>






</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2017 Aurthur
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="/js/jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>






<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  </div>
</body>
</html>